import { INPUT_FOCUS, INPUT_BLUR, MOUSE_ENTER, MOUSE_LEAVE, CHANGE_LIST, NEXT_LIST } from './constants'
import { fromJS } from 'immutable'

const defaultState = fromJS({
  focused: false,
  mouseIn: false,
  list:[],
  page:0,
  pageTotal:1
})

const reducer = (state = defaultState, action) =>{
  switch (action.type) {
    case INPUT_FOCUS:
      const newState = state.set('focused',true)
      return newState;
    case INPUT_BLUR:
      return state.set('focused',false)
    case MOUSE_ENTER:
      return state.set('mouseIn',true)
    case MOUSE_LEAVE:
      return state.set('mouseIn',false)
    case CHANGE_LIST:
      return state.merge({
        list: action.data,
        pageTotal: action.pageTotal
      })
    case NEXT_LIST:
      return state.set('page', action.page)
    default:
      return state
  }
}

export default reducer;
